package com.memo4android;

import com.memo4android.model.AppModel;
import com.memo4android.model.Dossier;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

public class ModifyFolderActivity extends Activity implements OnClickListener{
	private Dossier dossier;
	private AppModel model;
	private EditText edit; 
	
	public void onCreate(Bundle savedInstanceState){
		super.onCreate(savedInstanceState);
        setContentView(R.layout.frame_modify_note_folder);
        
        model = AppModel.getInstance(this);
        String folderName = getIntent().getStringExtra("folderName");
        
        setTitle(this.getTitle() + " - " + folderName);
        
        dossier = model.getDossier(folderName);
        edit = (EditText) findViewById(R.id.titleModifyNoteFolder);
        edit.setText(folderName);
        
        ((Button)this.findViewById(R.id.buttonCancelModifyNoteFolder)).setOnClickListener(this);
        ((Button)this.findViewById(R.id.buttonDeleteModifyNoteFolder)).setOnClickListener(this);
        ((Button)this.findViewById(R.id.buttonValidModifyNoteFolder)).setOnClickListener(this);
	}
	
    @Override
    public void onBackPressed(){
		Intent intent_allnotes = new Intent(this ,MainView.class);
		intent_allnotes.putExtra("label", "all notes");
		this.startActivity(intent_allnotes);    	
    }

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch(v.getId()){
		
		case R.id.buttonValidModifyNoteFolder:
			
	        if(dossier != null){ 
		        dossier.setTitre(edit.getText().toString());
		        model.saveFolderToBDD(dossier);
	        }
			
			this.finish();
			break;
			
		case R.id.buttonCancelModifyNoteFolder:
			this.finish();
			break;
			
		case R.id.buttonDeleteModifyNoteFolder:
			model.deleteDossier(dossier);
			model.deleteDossierFromBDD(dossier);
			this.finish();
			break;
		
		}
		
	}

}
